<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>android逆向之frida安装与简单使用Crackmes/Android/Level_01 | Zeo's Security Lab</title><meta name="author" content="Zeo"><meta name="copyright" content="Zeo"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="ffffff"><meta name="description" content="0x01 在电脑上安装adb安装adb我们要在电脑上通过adb与手机进行交互，所以要先安装adb 1.安装 adbwindows电脑安装adb 12可以通过安装android sdk然后就是 &#x2F;android sdk&#x2F;platform-tools&#x2F;adb.exe  Mac安装命令 1brew cask install android-platform-tools  2.将手机通过数据线连接到电">
<meta property="og:type" content="article">
<meta property="og:title" content="android逆向之frida安装与简单使用Crackmes&#x2F;Android&#x2F;Level_01">
<meta property="og:url" content="https://godzeo.github.io/2021/09/14/android%E9%80%86%E5%90%91%E4%B9%8Bfrida%E5%AE%89%E8%A3%85%E4%B8%8E%E7%AE%80%E5%8D%95%E4%BD%BF%E7%94%A8Crackmes!Android!Level_01/index.html">
<meta property="og:site_name" content="Zeo&#39;s Security Lab">
<meta property="og:description" content="0x01 在电脑上安装adb安装adb我们要在电脑上通过adb与手机进行交互，所以要先安装adb 1.安装 adbwindows电脑安装adb 12可以通过安装android sdk然后就是 &#x2F;android sdk&#x2F;platform-tools&#x2F;adb.exe  Mac安装命令 1brew cask install android-platform-tools  2.将手机通过数据线连接到电">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231225566.webp">
<meta property="article:published_time" content="2021-09-14T01:10:49.000Z">
<meta property="article:modified_time" content="2022-11-28T12:25:22.941Z">
<meta property="article:author" content="Zeo">
<meta property="article:tag" content="android python Frida">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231225566.webp"><link rel="shortcut icon" href="/img/WX20211124-162855.png"><link rel="canonical" href="https://godzeo.github.io/2021/09/14/android%E9%80%86%E5%90%91%E4%B9%8Bfrida%E5%AE%89%E8%A3%85%E4%B8%8E%E7%AE%80%E5%8D%95%E4%BD%BF%E7%94%A8Crackmes!Android!Level_01/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'android逆向之frida安装与简单使用Crackmes/Android/Level_01',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-11-28 20:25:22'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', 'ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"><link rel="alternate" href="/atom.xml" title="Zeo's Security Lab" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231013354.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">125</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">46</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> List</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> Music</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> Movie</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> About</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231225566.webp')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Zeo's Security Lab</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> List</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> Music</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> Movie</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> About</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">android逆向之frida安装与简单使用Crackmes/Android/Level_01</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-09-14T01:10:49.000Z" title="发表于 2021-09-14 09:10:49">2021-09-14</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-11-28T12:25:22.941Z" title="更新于 2022-11-28 20:25:22">2022-11-28</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/app%E6%B8%97%E9%80%8F/">app渗透</a></span></div><div class="meta-secondline"></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><span id="more"></span>

<h1 id="0x01-在电脑上安装adb"><a href="#0x01-在电脑上安装adb" class="headerlink" title="0x01 在电脑上安装adb"></a>0x01 在电脑上安装adb</h1><h2 id="安装adb"><a href="#安装adb" class="headerlink" title="安装adb"></a>安装adb</h2><p>我们要在电脑上通过adb与手机进行交互，所以要先安装adb</p>
<h2 id="1-安装-adb"><a href="#1-安装-adb" class="headerlink" title="1.安装 adb"></a>1.安装 adb</h2><p>windows电脑安装adb</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">可以通过安装android sdk</span><br><span class="line">然后就是 /android sdk/platform-tools/adb.exe</span><br></pre></td></tr></table></figure>

<p>Mac安装命令</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">brew cask install android-platform-tools</span><br></pre></td></tr></table></figure>

<h2 id="2-将手机通过数据线连接到电脑上"><a href="#2-将手机通过数据线连接到电脑上" class="headerlink" title="2.将手机通过数据线连接到电脑上"></a>2.将手机通过数据线连接到电脑上</h2><ul>
<li>要设置手机打开usb调试</li>
<li>一般就在 手机设置-关于-开发者选项-允许usb调试 （不同手机不一样，自己找找USB调试）</li>
</ul>
<h2 id="3-运行adb-在终端输入如下命令-查看连接的设备"><a href="#3-运行adb-在终端输入如下命令-查看连接的设备" class="headerlink" title="3.运行adb,在终端输入如下命令,查看连接的设备"></a>3.运行adb,在终端输入如下命令,查看连接的设备</h2><p>运行adb命令，查看当前连接设备</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">adb devices</span><br></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/img_convert/75249aca8a1e99fd5fb78ca8d825449b.png" alt="image-20210825203950358"></p>
<p>显示有device就是连接上了设备</p>
<h1 id="0x02-在电脑上-安装python3"><a href="#0x02-在电脑上-安装python3" class="headerlink" title="0x02 在电脑上-安装python3"></a>0x02 在电脑上-安装python3</h1><p>windows电脑去官网下载，自己百度安装吧</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">注意：高版本的frida 要配合高版本的python</span><br><span class="line">我的是 pyhton 3.7.9 和 frida 15.0.15</span><br></pre></td></tr></table></figure>

<p>Mac版本</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">brew install python@3.7</span><br></pre></td></tr></table></figure>

<h1 id="0x03-在电脑上安装frida-tools"><a href="#0x03-在电脑上安装frida-tools" class="headerlink" title="0x03 在电脑上安装frida-tools"></a>0x03 在电脑上安装frida-tools</h1><p>这个其实是python的一个模块，自动化编写hook脚本一定要引入的。</p>
<p>windows与Mac 的命令一样</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">python -m pip install frida-tools</span><br></pre></td></tr></table></figure>

<h1 id="0x04-在手机上安装frida-server"><a href="#0x04-在手机上安装frida-server" class="headerlink" title="0x04 在手机上安装frida-server"></a>0x04 在手机上安装frida-server</h1><ul>
<li><p>电脑上配置完后，手机端也需要配置</p>
<ul>
<li>现在需要下载frida-server端到手机中</li>
</ul>
</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">下载地址：</span><br><span class="line">https://github.com/frida/frida/releases</span><br></pre></td></tr></table></figure>

<p>版本很多</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/46518c7d41f003e20793ce89eb1fda89.png" alt="image-20210825213116374"></p>
<p>androids就是下面几个，对应去下载就好了</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">frida-server-15.0.18-android-arm.xz             ----真机32位 </span><br><span class="line">frida-server-15.0.18-android-arm64.xz           ----真机64位 </span><br><span class="line">frida-server-15.0.18-android-x86.xz             ----android模拟器32位 </span><br><span class="line">frida-server-15.0.18-android-x86_64.xz          ----android模拟器64位 </span><br></pre></td></tr></table></figure>

<ul>
<li><p>下载完android设备相对应的frida-server后</p>
</li>
<li><p>通过adb push将frida-server发送到android设备中</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">adb push /Users/zy/Desktop/frida-server/frida-server-12.10.4-android-arm  /data/local/tmp</span><br><span class="line"></span><br><span class="line">adb push （本机frida-server地址）（手机要放的地址）</span><br></pre></td></tr></table></figure></li>
</ul>
<p><img src="https://img-blog.csdnimg.cn/img_convert/7b18a9d117431a34c6cdc2f2ff7d0511.png" alt="image-20210825213522189"></p>
<ul>
<li><p>手机上启动frida-server</p>
</li>
<li><p>这样电脑上的frida客户端才能与手机中的frida服务端才可以进行交互</p>
</li>
<li><p>上述已经将frida-server放入 &#x2F;data&#x2F;local&#x2F;tmp中</p>
<p>启动adb shell 进入手机的shell中</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">#查看adb连接的设备</span><br><span class="line">adb devices</span><br><span class="line">#启动adb shell 进入手机的shell中</span><br><span class="line">adb shell</span><br></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/img_convert/178f9011c666b5c4570f220639d3394e.png" alt="image-20210825213820963"></p>
</li>
<li><p>找到frida-server，给他执行权限，运行</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"># 进入手机shell</span><br><span class="line">adb shell</span><br><span class="line"># 找到对应目录</span><br><span class="line">cd /data/local/tmp/</span><br><span class="line"># 给运行权限</span><br><span class="line">chmod 775 frida-server-15-arm64</span><br><span class="line"># 后台持久运行，如果运行一次就直接 ./frida-server-15-arm64</span><br><span class="line">./frida-server-15-arm64 &amp;</span><br></pre></td></tr></table></figure>

<p>下面是我的命令</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/4b3415baa471b52f5d2ba74fffb7d8a6.png" alt="image-20210825214647006"></p>
</li>
</ul>
<h1 id="0x05-frida的使用"><a href="#0x05-frida的使用" class="headerlink" title="0x05 frida的使用"></a>0x05 frida的使用</h1><p>安装完之后，就是怎么使用frida了</p>
<p><strong>注意：</strong></p>
<p>刚刚在手机端安装好frida-server的时候，发现frida命令有的可用有的不可用，比如frida-ps -U 可执行，而frida-ps -R 就会执行报错（Failed to enumerate processes: unable to connect to remote frida-server），原因发现需要在客户端开启端口转发才可以</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">adb forward tcp:27042 tcp:27042 </span><br></pre></td></tr></table></figure>

<p>命令做了端口开启，才使得问题解决</p>
<p>frida tools主要有这几个常用的功能</p>
<ul>
<li><strong>frida-ls-devices</strong> 查看设备信息，主要包括<strong>UDID</strong>、<strong>连接方式</strong>、<strong>iOS设备名称</strong>，如下所示</li>
</ul>
<p><img src="https://img-blog.csdnimg.cn/img_convert/d25682948f46b37d41c6089668836cf2.png" alt="image-20210825215527181"></p>
<ul>
<li><strong>frida-ps</strong> 查看通过USB连接的iOS设备上运行的程序</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">通常使用frida-ps -Ua  查看正在运行的应用</span><br><span class="line">通常使用frida-ps -Uai 查看已经安装的应用程序</span><br></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/img_convert/f43c77edaa4dc3dd99bd8a60011e4aea.png" alt="image-20210825215811929"></p>
<p>[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-GDTyv1if-1631581506681)(<a target="_blank" rel="noopener" href="https://gitee.com/godzeo/blogimg/raw/master/img/20210825220111.png/)/]">https://gitee.com/godzeo/blogimg/raw/master/img/20210825220111.png\)\]</a></p>
<ul>
<li><strong>frida-trace</strong></li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">frida-ps -D &lt;UDID&gt; 通过UDID查看设备中应用程序中的pid、进程名</span><br></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/img_convert/c1769b264e441c33659c361f1dd0f24c.png" alt="image-20210825220327085"></p>
<ul>
<li>**frida-kill ** 结束某个机子的进程</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">frida-kill -D &lt;UDID&gt; &lt;pid&gt;</span><br></pre></td></tr></table></figure>

<h1 id="0x06-通过python及JavaScript脚本自动化来hook"><a href="#0x06-通过python及JavaScript脚本自动化来hook" class="headerlink" title="0x06 通过python及JavaScript脚本自动化来hook"></a>0x06 通过python及JavaScript脚本自动化来hook</h1><ul>
<li>下面就是，frida还可以通过python及JavaScript脚本来hook android设备中的应用程序</li>
<li>这个python调用和注入脚本，基本上都是固定的，只需要修改准备hook的app的bundleId和javaScript脚本地址就好了</li>
</ul>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># author: Zeo</span></span><br><span class="line"><span class="comment"># python: 3.7 </span></span><br><span class="line"><span class="comment"># datetime:2021/8/23 6:30 下午</span></span><br><span class="line"><span class="comment"># software: PyCharm</span></span><br><span class="line"></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">文件说明：通过python及JavaScript脚本自动化来hook </span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="comment">#导入frida模块</span></span><br><span class="line"><span class="keyword">import</span> frida, sys </span><br><span class="line"><span class="comment">#准备执行的frida javaScript脚本</span></span><br><span class="line">script = <span class="string">&#x27;Frida-Mobile-Scripts/Android/system_exit_bypass.js&#x27;</span> </span><br><span class="line"><span class="comment">#准备hook的app的bundleId</span></span><br><span class="line">bundle = <span class="string">&#x27;owasp.mstg.uncrackable1&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#打开frida脚本，读取frida脚本</span></span><br><span class="line">f = <span class="built_in">open</span>(script, <span class="string">&quot;r&quot;</span>) </span><br><span class="line">s = f.read() </span><br><span class="line"></span><br><span class="line"><span class="comment">#连接usb设备 1000表示超时</span></span><br><span class="line">device = frida.get_usb_device(<span class="number">1000</span>) </span><br><span class="line"><span class="comment">#启动指定bundleId的app</span></span><br><span class="line">pid = device.spawn([bundle])</span><br><span class="line"><span class="comment">#附加到app</span></span><br><span class="line">session = device.attach(pid)</span><br><span class="line"><span class="comment">#创建frida javaScript脚本</span></span><br><span class="line">script = session.create_script(s)</span><br><span class="line"><span class="comment">#load脚本到app进程中 这样即注入成功</span></span><br><span class="line">script.load() </span><br><span class="line"><span class="comment">#恢复app运行</span></span><br><span class="line">device.resume(pid) </span><br><span class="line"><span class="comment">#读取打印日志</span></span><br><span class="line">sys.stdin.read()</span><br></pre></td></tr></table></figure>

<h1 id="0x07-安装测试应用，简单使用"><a href="#0x07-安装测试应用，简单使用" class="headerlink" title="0x07 安装测试应用，简单使用"></a>0x07 安装测试应用，简单使用</h1><p>下载完以后通过adb 将apk安装到手机中</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">adb install UnCrackable-Level1.apk</span><br></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/img_convert/62dad13b8a9bd2fb9aea19e1b118b0ea.png" alt="image-20210825201232862"></p>
<p>下载地址：</p>
<p><em><strong><a target="_blank" rel="noopener" href="https://github.com/OWASP/owasp-mstg/tree/master/Crackmes/Android/Level/_01">https://github.com/OWASP/owasp-mstg/tree/master/Crackmes/Android/Level\_01</a></strong></em></p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/a5bb4b8fcb56afef20047975aea4eeaa.png" alt="WechatIMG119"></p>
<h2 id="一个root检测的绕过"><a href="#一个root检测的绕过" class="headerlink" title="一个root检测的绕过"></a>一个root检测的绕过</h2><h2 id="1、反编译静态分析app"><a href="#1、反编译静态分析app" class="headerlink" title="1、反编译静态分析app"></a>1、反编译静态分析app</h2><p>我们常用的工具有jeb、jadx等工具进行分析</p>
<p>这里我推荐使用jadx反编译分析。</p>
<p>打开软件，直接打开要反编译的APK就可以了</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/755621ad18ac23cbb92fcc204e48ed8d.png" alt="image-20210831101758315"></p>
<h2 id="2、分析app的检测android设备是否root的功能"><a href="#2、分析app的检测android设备是否root的功能" class="headerlink" title="2、分析app的检测android设备是否root的功能"></a>2、分析app的检测android设备是否root的功能</h2><p>根据提示的字符串找到这个检测函数</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/541ad0c815d2e27094a063c2a1fd8819.png" alt="image-20210831101926899"></p>
<p>root检测主要靠三个函数</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">c.a() c.b() c.c() </span><br></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/img_convert/0e939665965a8d08f2557d7f062e8ddc.png" alt="image-20210831102019408"></p>
<p>基本上就是通过 环境变量 PATH检测、test-key文件、或者一下目录或者文件检测是否root</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/47302d28a5e7a3254b1476e7e20fa8ca.png"></p>
<p>但其实不用这么麻烦，可以直接hook System.exit函数，app虽然检测到我们的设备已经root，但是不让它退出，继续运行也是一样的效果</p>
<h2 id="3、编写hook-js脚本"><a href="#3、编写hook-js脚本" class="headerlink" title="3、编写hook js脚本"></a>3、编写hook js脚本</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">Java.perform(function () &#123;</span><br><span class="line">    const System = Java.use(&#x27;java.lang.System&#x27;)</span><br><span class="line"></span><br><span class="line">    console.log(&quot;--&gt; System.exit() Bypass - Script Loaded&quot;)</span><br><span class="line">    System.exit.implementation = function()&#123;</span><br><span class="line">        console.log(&quot;System.exit() Bypassed!&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<p>点击之后就成功绕过退出了</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/6413bb4baa1fc91a4b5c0ca3a716163e.png" alt="WechatIMG120"></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://godzeo.github.io">Zeo</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://godzeo.github.io/2021/09/14/android%E9%80%86%E5%90%91%E4%B9%8Bfrida%E5%AE%89%E8%A3%85%E4%B8%8E%E7%AE%80%E5%8D%95%E4%BD%BF%E7%94%A8Crackmes!Android!Level_01/">https://godzeo.github.io/2021/09/14/android%E9%80%86%E5%90%91%E4%B9%8Bfrida%E5%AE%89%E8%A3%85%E4%B8%8E%E7%AE%80%E5%8D%95%E4%BD%BF%E7%94%A8Crackmes!Android!Level_01/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://godzeo.github.io" target="_blank">Zeo's Security Lab</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/android-python-Frida/">android python Frida</a></div><div class="post_share"><div class="social-share" data-image="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231225566.webp" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2021/09/24/%E5%88%A9%E7%94%A8PHP_SESSION_UPLOAD_PROGRESS%E4%B8%8A%E4%BC%A0webshell/"><img class="prev-cover" src="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231225559.webp" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">利用PHP_SESSION_UPLOAD_PROGRESS上传webshell</div></div></a></div><div class="next-post pull-right"><a href="/2021/08/31/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E6%B8%97%E9%80%8F%E6%B5%8B%E8%AF%95-%E5%89%8D%E7%AB%AF%E6%89%93%E5%8C%85%E8%B0%83%E8%AF%95%E8%A7%A3%E5%AF%86/"><img class="next-cover" src="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231217732.webp" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">小程序渗透测试-前端打包调试解密</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231013354.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Zeo</div><div class="author-info__description">专注于安全,分享生活,分享知识</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">125</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">46</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/godzeo"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/godzeo" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:zzzhhhaaaiiii@gmail.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">Weclome my blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#0x01-%E5%9C%A8%E7%94%B5%E8%84%91%E4%B8%8A%E5%AE%89%E8%A3%85adb"><span class="toc-number">1.</span> <span class="toc-text">0x01 在电脑上安装adb</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85adb"><span class="toc-number">1.1.</span> <span class="toc-text">安装adb</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E5%AE%89%E8%A3%85-adb"><span class="toc-number">1.2.</span> <span class="toc-text">1.安装 adb</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E5%B0%86%E6%89%8B%E6%9C%BA%E9%80%9A%E8%BF%87%E6%95%B0%E6%8D%AE%E7%BA%BF%E8%BF%9E%E6%8E%A5%E5%88%B0%E7%94%B5%E8%84%91%E4%B8%8A"><span class="toc-number">1.3.</span> <span class="toc-text">2.将手机通过数据线连接到电脑上</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E8%BF%90%E8%A1%8Cadb-%E5%9C%A8%E7%BB%88%E7%AB%AF%E8%BE%93%E5%85%A5%E5%A6%82%E4%B8%8B%E5%91%BD%E4%BB%A4-%E6%9F%A5%E7%9C%8B%E8%BF%9E%E6%8E%A5%E7%9A%84%E8%AE%BE%E5%A4%87"><span class="toc-number">1.4.</span> <span class="toc-text">3.运行adb,在终端输入如下命令,查看连接的设备</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#0x02-%E5%9C%A8%E7%94%B5%E8%84%91%E4%B8%8A-%E5%AE%89%E8%A3%85python3"><span class="toc-number">2.</span> <span class="toc-text">0x02 在电脑上-安装python3</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#0x03-%E5%9C%A8%E7%94%B5%E8%84%91%E4%B8%8A%E5%AE%89%E8%A3%85frida-tools"><span class="toc-number">3.</span> <span class="toc-text">0x03 在电脑上安装frida-tools</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#0x04-%E5%9C%A8%E6%89%8B%E6%9C%BA%E4%B8%8A%E5%AE%89%E8%A3%85frida-server"><span class="toc-number">4.</span> <span class="toc-text">0x04 在手机上安装frida-server</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#0x05-frida%E7%9A%84%E4%BD%BF%E7%94%A8"><span class="toc-number">5.</span> <span class="toc-text">0x05 frida的使用</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#0x06-%E9%80%9A%E8%BF%87python%E5%8F%8AJavaScript%E8%84%9A%E6%9C%AC%E8%87%AA%E5%8A%A8%E5%8C%96%E6%9D%A5hook"><span class="toc-number">6.</span> <span class="toc-text">0x06 通过python及JavaScript脚本自动化来hook</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#0x07-%E5%AE%89%E8%A3%85%E6%B5%8B%E8%AF%95%E5%BA%94%E7%94%A8%EF%BC%8C%E7%AE%80%E5%8D%95%E4%BD%BF%E7%94%A8"><span class="toc-number">7.</span> <span class="toc-text">0x07 安装测试应用，简单使用</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%80%E4%B8%AAroot%E6%A3%80%E6%B5%8B%E7%9A%84%E7%BB%95%E8%BF%87"><span class="toc-number">7.1.</span> <span class="toc-text">一个root检测的绕过</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1%E3%80%81%E5%8F%8D%E7%BC%96%E8%AF%91%E9%9D%99%E6%80%81%E5%88%86%E6%9E%90app"><span class="toc-number">7.2.</span> <span class="toc-text">1、反编译静态分析app</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2%E3%80%81%E5%88%86%E6%9E%90app%E7%9A%84%E6%A3%80%E6%B5%8Bandroid%E8%AE%BE%E5%A4%87%E6%98%AF%E5%90%A6root%E7%9A%84%E5%8A%9F%E8%83%BD"><span class="toc-number">7.3.</span> <span class="toc-text">2、分析app的检测android设备是否root的功能</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3%E3%80%81%E7%BC%96%E5%86%99hook-js%E8%84%9A%E6%9C%AC"><span class="toc-number">7.4.</span> <span class="toc-text">3、编写hook js脚本</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2022/11/28/Nosql%20inject%E6%B3%A8%E5%85%A5/" title="Nosql inject注入"><img src="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231217732.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Nosql inject注入"/></a><div class="content"><a class="title" href="/2022/11/28/Nosql%20inject%E6%B3%A8%E5%85%A5/" title="Nosql inject注入">Nosql inject注入</a><time datetime="2022-11-28T07:28:02.000Z" title="发表于 2022-11-28 15:28:02">2022-11-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/11/15/%E4%BC%81%E4%B8%9A%20SDLC%20%E5%AE%89%E5%85%A8%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E7%AE%A1%E7%90%86/" title="企业 SDLC 安全生命周期管理"><img src="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231217732.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="企业 SDLC 安全生命周期管理"/></a><div class="content"><a class="title" href="/2022/11/15/%E4%BC%81%E4%B8%9A%20SDLC%20%E5%AE%89%E5%85%A8%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E7%AE%A1%E7%90%86/" title="企业 SDLC 安全生命周期管理">企业 SDLC 安全生命周期管理</a><time datetime="2022-11-15T14:03:44.000Z" title="发表于 2022-11-15 22:03:44">2022-11-15</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/11/05/Go%20%E4%BB%A3%E7%A0%81%E5%AE%A1%E8%AE%A1%E6%BC%8F%E6%B4%9E(File%20Operation!Redirect!Cors)/" title="Go 代码审计漏洞(File Operation\Redirect\Cors)"><img src="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231225566.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Go 代码审计漏洞(File Operation\Redirect\Cors)"/></a><div class="content"><a class="title" href="/2022/11/05/Go%20%E4%BB%A3%E7%A0%81%E5%AE%A1%E8%AE%A1%E6%BC%8F%E6%B4%9E(File%20Operation!Redirect!Cors)/" title="Go 代码审计漏洞(File Operation\Redirect\Cors)">Go 代码审计漏洞(File Operation\Redirect\Cors)</a><time datetime="2022-11-05T09:15:28.000Z" title="发表于 2022-11-05 17:15:28">2022-11-05</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/10/30/Go%20%E4%BB%A3%E7%A0%81%E5%AE%A1%E8%AE%A1%E9%AB%98%E5%8D%B1%E6%BC%8F%E6%B4%9E(sqli!cmd!ssrf)/" title="Go 代码审计高危漏洞(sqli\cmd\ssrf)"><img src="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231225566.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Go 代码审计高危漏洞(sqli\cmd\ssrf)"/></a><div class="content"><a class="title" href="/2022/10/30/Go%20%E4%BB%A3%E7%A0%81%E5%AE%A1%E8%AE%A1%E9%AB%98%E5%8D%B1%E6%BC%8F%E6%B4%9E(sqli!cmd!ssrf)/" title="Go 代码审计高危漏洞(sqli\cmd\ssrf)">Go 代码审计高危漏洞(sqli\cmd\ssrf)</a><time datetime="2022-10-30T06:57:14.000Z" title="发表于 2022-10-30 14:57:14">2022-10-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/05/10/Java%E4%BB%A3%E7%A0%81%E5%AE%A1%E8%AE%A1%EF%BC%9A%20ClassLoader%E5%BA%94%E7%94%A8/" title="Java代码审计： ClassLoader应用"><img src="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231225566.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Java代码审计： ClassLoader应用"/></a><div class="content"><a class="title" href="/2022/05/10/Java%E4%BB%A3%E7%A0%81%E5%AE%A1%E8%AE%A1%EF%BC%9A%20ClassLoader%E5%BA%94%E7%94%A8/" title="Java代码审计： ClassLoader应用">Java代码审计： ClassLoader应用</a><time datetime="2022-05-10T08:21:21.000Z" title="发表于 2022-05-10 16:21:21">2022-05-10</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2019 - 2022 By Zeo</div><div class="footer_custom_text">Hi, welcome to my blog!</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><div class="js-pjax"></div></div></body></html>